# Maintainer: Alexander F. Rødseth <xyproto@archlinux.org>
# Contributor: Romain Gautier <romain.gautier@nimamoh.com>

pkgname=kotlin
pkgver=1.8.20
pkgrel=1
pkgdesc='Statically typed programming language that can interoperate with Java'
arch=(any)
url='https://kotlinlang.org/'
license=(APACHE custom)
depends=('java-environment>=8')
makedepends=(setconf)
source=("https://github.com/JetBrains/kotlin/releases/download/v${pkgver/_/-}/kotlin-compiler-${pkgver/_/-}.zip")
sha512sums=('8b8e76c18b00157da7790bcda82788772ba51cd8381220a29f7235abac6083f96f909566ea5abe43d300b575bc4c6e967eafe2f062ce28c865f6e96b72f4ca21')
b2sums=('a09d58f93b03b219c26deed3495c61221ea973ec951e26b6a40deffe0e9d79e8464313fa02684b7c6141d21902702bd19a065678e82091ff33b4b9e7c62c38bf')

prepare() {
  cd ${pkgname}c/bin

  setconf kotlin      DIR         /usr/bin
  setconf kotlinc-js  DIR         /usr/bin
  setconf kotlinc-jvm DIR         /usr/bin
  setconf kotlinc     KOTLIN_HOME /usr/share/$pkgname
}

package() {
  cd ${pkgname}c

  # executables
  install -Dm755 -t "$pkgdir/usr/bin" bin/kotlin
  install -Dm755 -t "$pkgdir/usr/bin" bin/kotlinc
  install -Dm755 -t "$pkgdir/usr/bin" bin/kotlinc-js
  install -Dm755 -t "$pkgdir/usr/bin" bin/kotlinc-jvm

  # jar files
  cd lib
  install -d "$pkgdir/usr/share/$pkgname/lib"
  for jar in *.jar; do
    install -Dm644 "$jar" "$pkgdir/usr/share/$pkgname/lib"
  done

  # licenses
  cd "$srcdir/${pkgname}c/license"
  install -d "$pkgdir/usr/share/licenses/$pkgname"
  install -Dm644 LICENSE.txt "$pkgdir/usr/share/licenses/$pkgname"
  install -Dm644 NOTICE.txt "$pkgdir/usr/share/licenses/$pkgname"
  for txt in third_party/*.txt; do
    install -Dm644 "$txt" "$pkgdir/usr/share/licenses/$pkgname"
  done

  # build.txt must be installed for for "-version" to work
  cd $srcdir/${pkgname}c
  install -Dm644 build.txt "$pkgdir/usr/share/$pkgname"
}

# getver: github.com/JetBrains/kotlin/releases/latest
